<?php
include("include/config.inc.php");
$msg="";
if(isset($_REQUEST['userIns']))
{
	$useName=$_POST['userName'];
	$usePass=$_POST['userpassword'];
	$useComPass=$_POST['userpasswordCom'];
	if($usePass == $useComPass)
	{
	  $insUserQuery="INSERT INTO  `user` (`userName` ,`password` ,`userType`)
	               VALUES ( '".$useName."',  '".$usePass."', 'Admin')";
	               
	  $insUserQueryRes=mysql_query($insUserQuery);
	
  }
  else
  {
  	$msg = "Password are not match..";
  }
}

$o=0;
$branchArray = array();
$a = "SELECT branchId,branchName
                   FROM branch";
$selectBranchRes = mysql_query($a);
while($branchRow = mysql_fetch_array($selectBranchRes))
{
	$branchArray['branchId'][$o]   = $branchRow['branchId'];
	$branchArray['branchName'][$o] = $branchRow['branchName'];
	$o++;
}
  
////select Branch : Start  
$userArr = array();
$i=0;
$selUser="SELECT userId,userName,password,userType,branchName
            FROM user
            LEFT JOIN branch ON user.branchId = branch.branchId
           WHERE userType='Admin'";
$selUserRes=mysql_query($selUser);
while($selUserResRow=mysql_fetch_array($selUserRes))
{
	$userArr[$i]['userId']     = $selUserResRow['userId'];
	$userArr[$i]['userName']   = $selUserResRow['userName'];
	$userArr[$i]['branchName'] = $selUserResRow['branchName'];
	$userArr[$i]['password']   = $selUserResRow['password'];
	$userArr[$i]['userType']   = $selUserResRow['userType'];
	$i++;
}
////select Branch : End

if(isset($_GET['userId']))
{
  	if($_GET['userId'] != "")
  	{
  		$delUserQue="DELETE FROM user 
  		              WHERE userId=".$_GET['userId'];
  		              
  		$delUserQueRes=mysql_query($delUserQue);
  		
  	}
	header("location:list.php");
}
include("./bottom.php");
$smarty->assign("msg",$msg);
$smarty->assign("userArr",$userArr);
$smarty->assign("branchArray",$branchArray);
$smarty->display('list.tpl');
?>